package com.example.travelservlet.like.controller;

import com.example.travelservlet.entity.Like;
import com.example.travelservlet.entity.LikeDto;
import com.example.travelservlet.like.service.LikeService;
import com.example.travelservlet.user.domain.Result;
import com.example.travelservlet.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hxy
 * @date 2023/5/10 8:43
 */
@RestController
@RequestMapping("/likeController")
public class LikeController {
    @Autowired
    private LikeService likeService;

    @GetMapping("/insertLike/{userId}/{id}/{type}")
    public Integer insertLike(@PathVariable String userId,@PathVariable String id,@PathVariable int type){
        Like like = new Like();
        like.setId(id);
        like.setUserId(userId);
        like.setType(type);
        Integer integer = likeService.insertLike(like);

        return integer;
    }

    @GetMapping("/deleteLike/{userId}/{id}")
    public Integer deleteLike(@PathVariable String userId,@PathVariable String id){
        Integer integer = likeService.deleteLike(userId, id);
        return integer;
    }

    @GetMapping("/findLikeByType/{userId}/{type}")
    public Result<List<LikeDto>> findLikeByUserIdAndType(@PathVariable String userId,@PathVariable Integer type){
        List<LikeDto> likeByUserIdAndType = likeService.findLikeByUserIdAndType(userId, type);
        return ResultUtil.success(likeByUserIdAndType);
    }

}
